<!DOCTYPE html>
<html>
	<head>
		<meta charset="UTF-8">
		<title></title>
		<link rel="stylesheet" href="#(CONTEXT_PATH)/static/lib/layui/css/layui.css">
		<script type="text/javascript" src="https://cdn.bootcss.com/jquery/3.2.1/jquery.min.js"></script>
		<script src="#(CONTEXT_PATH)/static/lib/layui/layui.js" charset="utf-8"></script> 
	</head>
	<body>
		<br>
		<form id="editForm" class="layui-form" action="" onsubmit="submitForm()" style="width:90%">
		  <div class="layui-form-item">
		    <label class="layui-form-label">用户名</label>
		    <div class="layui-input-block">
		      <input type="hidden" id="id" name="id" value="#(user.id??)"  />
		      <input type="text" name="username"  value="#(user.username??)"  lay-verify="username" autocomplete="off" placeholder="请输入" class="layui-input">
		    </div>
		  </div>
		  <div class="layui-form-item">
		    <label class="layui-form-label">密码</label>
		    <div class="layui-input-block">
		      <input type="text" name="password"  value="#(user.password??)"  lay-verify="password" autocomplete="off" placeholder="请输入" class="layui-input">
		    </div>
		  </div>
		   <div class="layui-form-item">
		    <label class="layui-form-label">公司名称</label>
		    <div class="layui-input-block">
		      <input type="text" name="company_name"  value="#(user.company_name??)"  lay-verify="company_name" autocomplete="off" placeholder="请输入" class="layui-input">
		    </div>
		  </div>
		 <div class="layui-form-item">
		    <label class="layui-form-label">姓名</label>
		    <div class="layui-input-block">
		      <input type="text" name="name"  value="#(user.name??)"  lay-verify="name" autocomplete="off" placeholder="请输入" class="layui-input">
		    </div>
		  </div>
		  
		  <div class="layui-form-item">
		    <label class="layui-form-label">积分</label>
		    <div class="layui-input-block">
		      <input type="text" name="score"  value="#(user.score??)"  lay-verify="score" autocomplete="off" placeholder="请输入" class="layui-input">
		    </div>
		  </div>
		  <div class="layui-form-item">
		    <label class="layui-form-label">是VIP</label>
		    <div class="layui-input-block" style="line-height:38px;">
		    #if(user.is_vip) 是  #else 否 #end
		    </div>
		  </div>
		  
		  <div class="layui-form-item">
		    <label class="layui-form-label">类型</label>
		    <div class="layui-input-block">
		    	<select  id="type" name="type"  >
		    		<option value="admin">超级管理员</option>
		    		<option value="manager">管理员</option>
		    		<option value="customer">会员</option>
		    	</select>
		    </div>
		  </div>
		  <div class="layui-form-item">
		    <label class="layui-form-label">生日</label>
		    <div class="layui-input-block">
		      <input type="text" id="birthday" name="birthday"  value="#(user.birthday??)"  lay-verify="birthday" autocomplete="off" placeholder="请输入" class="layui-input">
		    </div>
		  </div>
  		</form>
  		
   		<div class="layui-form-item">
		    <div class="layui-input-block">
		      <button class="layui-btn" onclick="submitData();">立即提交</button>
		    </div>
		  </div>
	</body>
	<script>
		var layer;
		var element;
		$(function(){
			layui.use(['form','element','laydate'],
			    function() {
		        layer = layui.layer;
		        element = layui.element;
		        var laydate = layui.laydate;
		        
		        //执行一个laydate实例
		        laydate.render({
		          elem: '#birthday' //指定元素
		        });
		     });

		     $("#type").val('#(user.type??)');
		});
		
		function refresh(){
			console.log("aaa " + parent.currentTab);
			var obj = getCurrentTab();
			var src = obj.attr("src");
			alert(src);
		}
		
		function getCurrentTab(){
			var obj = parent.$("iframe[class='x-iframe']:eq("+parent.currentTab+")");
			return obj[0];
		}
		
		function submitData(){
			var formData = $("#editForm").serialize();
			//console.log(formData);
            //formData.append('b', 3);// 还可以添加额外的表单数据
            $.post('#(CONTEXT_PATH)/user/save',formData,function(data) {
				//alert('完成');
				var obj = getCurrentTab();
				console.log(obj);
				obj.contentWindow.query();
           });
		}
		
		function submitForm(){
			submitData();
		}

		
	</script>
</html>
